class BaseAction:
    def __init__(self, driver):
        self.driver = driver

    # 定位元素
    def find_e(self, feature):
        return self.driver.find_element(*feature)

    # 输入内容
    def input(self, feature, context):
        return self.find_e(feature).send_keys(context)

    # 点击元素
    def click(self, feature):
        return self.find_e(feature).click()

    # 清空
    def clear(self, feature):
        return self.find_e(feature).clear()

    # 切换 iframe
    def switch_to_frame(self, frame_feature):
        return self.driver.switch_to.frame(self.find_e(frame_feature))

    # 切换回默认页面
    def switch_to_default(self):
        return self.driver.switch_to.default_content()

    # 切换窗口
    def switch_new_window(self):
        # 获取所有窗口句柄
        handles = self.driver.window_handles
        # python中-1下标表示从右往左, 第一个元素, 在这里即最新打开的窗口
        return self.driver.switch_to.window(handles[-1])